<#assign ctx="${rc.contextPath}">
<html>
<head>
    <title>新增/编辑定时任务</title>
    <script type="text/javascript">
        function save() {
            if ($("#frmEdit").form('validate') && checkForm("frmEdit")) {
                var data = $("#frmEdit").serializeObject();
                var params = new Object();
                $("#parameters").find(".form-item").each(function () {
                    var key = $(this).find(".form-field input")[0];
                    var value = $(this).find(".form-field input")[1];
                    var keyName = $(key).val();
                    var valueName = $(value).val();
                    params[keyName] = valueName;
                });
                data.dataMap = params;
                $.ajax({
                    type: "POST",
                    url: $("#frmEdit").attr('action'),
                    data: data,
                    dataType: 'json',
                    success: function (result) {
                        successMsg(result.message);
                        if (result.status == 200) {
                            window.location.href = "${ctx}/quartz/manage/page/";
                        }
                    }
                });
            }
        }

        function addParameter() {
            var html = template('param');
            var targetObj = $("#parameters").append(html);
            //easyui 重新渲染
            $.parser.parse(targetObj)
        }

        function cancel() {
            window.location.href = "${ctx}/quartz/manage/page/";
        }

        function checkName() {
            var name = $('#accUserName').val();
            var id = $('#accUserId').val();
            if (name == "") {
                $.messager.alert("提示", "名称不能为空", "warning")
                return;
            }
            $.ajax({
                type: "POST",
                url: '${ctx}/account/user/checkName',
                data: {'accUserName': name, 'id': id},
                dataType: 'json',
                success: function (result) {
                    successMsg(result.message);
                }
            });
        }
    </script>
</head>
<body>
<div class="breadcrumb"> 定时任务 > 定时任务管理 > 新增/编辑</div>

<div class="toolbar">
    <input type="button" class="btn btn-primary" onclick="save()" value="保存">
    <input type="button" class="btn btn-primary" onclick="addParameter()" value="新增参数">
    <input type="button" class="btn" onclick="cancel()" value="取消">
</div>

<form class="form-horizontal form-edit" id="frmEdit" action="${ctx}/quartz/manage/save">
    <fieldset class="dg-fieldset">
        <legend>定时任务信息</legend>
        <input type="hidden" name="jobName" value="${scheduleJob.jobName!}">
        <input type="hidden" name="jobGroupName" value="${scheduleJob.jobGroupName!}">

        <div class="form-item">
            <div class="form-lab">任务名：<span class="must">*</span></div>
            <div class="form-field">
                <input class="easyui-validatebox text" name="triggerName" id="triggerName"
                       value="${scheduleJob.triggerName!}" data-options="required:true"/>
            <#if scheduleJob.triggerName??>
            <#else>
                <a href="#" onclick="checkName()">&nbsp;检测用任务名是否可用</a>
            </#if>
            </div>
        </div>
        <div class="form-item">
            <div class="form-lab">任务组名：<span class="must">*</span></div>
            <div class="form-field">
                <input class="easyui-validatebox text" name="triggerGroupName" id="triggerGroupName"
                       value="${scheduleJob.triggerGroupName!}" data-options="required:true"/>
            </div>
        </div>
        <div class="form-item">
            <div class="form-lab">任务类型：<span class="must">*</span></div>
            <div class="form-field">
                串行：<input type="radio" name="isNonConcurrent" value="true"
                          <#if scheduleJob.isNonConcurrent>checked="checked"</#if>
                          style="position: relative; top:2px;"/>
                并行：<input type="radio" name="isNonConcurrent" value="false"
                          <#if !scheduleJob.isNonConcurrent>checked="checked"</#if>
                          style="position: relative; top:2px;"/>
            </div>
        </div>
        <div class="form-item">
            <div class="form-lab">起止时间：<span class="must">*</span></div>
            <div class="form-field">
                <input id="startTime" name="startTime" value="${(scheduleJob.startTime?string("yyyy-MM-dd HH:mm:ss"))!}"
                       class="easyui-datetimebox" style="width:152px;" required="true"/>
                —
                <input id="endTime" name="endTime" value="${(scheduleJob.endTime?string("yyyy-MM-dd HH:mm:ss"))!}"
                       class="easyui-datetimebox" style="width:152px;" required="true"/>
            </div>
        </div>
        <div class="form-item">
            <div class="form-lab">Cron表达式：<span class="must">*</span></div>
            <div class="form-field">
                <input id="cronExpression" name="cronExpression" value="${scheduleJob.cronExpression!}"
                       class="easyui-validatebox text" required="true"/>
            </div>
        </div>
        <div class="form-item">
            <div class="form-lab">备注：</div>
            <div class="form-field">
                <input id="desc" name="desc" value="${scheduleJob.desc!}" class="text"/>
            </div>
        </div>
    </fieldset>

    <fieldset class="dg-fieldset" id="parameters">
        <legend>参数列表</legend>
    <#if scheduleJob.dataMap??>
        <#list scheduleJob.dataMap?keys as key>
            <div class="form-item">
                <div class="form-lab">
                    <input class="btn btn-primary" type="button" onclick="this.parentNode.parentNode.remove()"
                           value="删除"/>
                </div>
                <div class="form-field">
                    参数名：<input type="text" value="${key!}" class="easyui-validatebox text" required="true"/>
                    参数值：<input type="text" value="${scheduleJob.dataMap[key]!}" class="easyui-validatebox text"
                               required="true"/>
                </div>
            </div>
        </#list>
    </#if>
    </fieldset>
</form>

<script id="param" type="text/html">
    <div class="form-item">
        <div class="form-lab">
            <input class="btn btn-primary" type="button" onclick="this.parentNode.parentNode.remove()" value="删除"/>
        </div>
        <div class="form-field">
            参数名：<input type="text" class="easyui-validatebox text" required="true"/>
            参数值：<input type="text" class="easyui-validatebox text" required="true"/>
        </div>
    </div>
</script>
</body>
</html>